﻿using System;
using System.Collections.Generic;
using WindowsGame.Common;
using WindowsGame.Common.Data;
using WindowsGame.Common.Static;
using NUnit.Framework;

namespace WindowsGame.SystemTests.Library.Managers
{
	[TestFixture]
	public class FileManagerTests : BaseSystemTests
	{
#pragma warning disable 618
		[TestFixtureSetUp]
#pragma warning restore 618
		public new void TestFixtureSetUp()
		{
			// System under test.
			FileManager = MyGame.Manager.FileManager;
		}

		[Test]
		public void BoardDataTest()
		{
			String boardFile = GetPath(Constants.BOARD_DATA_FILENAME);

			IList<String> lines = FileManager.LoadTxt(boardFile);
			String line = lines[0];

			BoardType boardType = (BoardType)Enum.Parse(typeof(BoardType), line, true);
			Assert.AreEqual(BoardType.Small, boardType);
		}

		[Test]
		public void SnakeDataTest()
		{
			String snakeFile = GetPath(Constants.SNAKE_DATA_FILENAME);
			SnakeData[] snakeData = FileManager.LoadXml<SnakeData[]>(snakeFile);
			Assert.AreEqual(8, snakeData.Length);

			SnakeData snake = snakeData[0];
			Assert.AreEqual(10, snake.StartPosX);
			Assert.AreEqual(5, snake.StartPosY);
			Assert.AreEqual(Direction.Left, snake.Direction);
			Assert.AreEqual(20, snake.TailLength);
			Assert.AreEqual(50, snake.TimeOnTile);
			Assert.AreEqual(10, snake.TileToMove);
		}

		private static String GetPath(String name)
		{
			return GetPath(Constants.DATA_DIRECTORY, name);
		}
		private static String GetPath(String fldr, String name)
		{
			String path = String.Format("{0}/{1}/{2}", Constants.CONTENT_DIRECTORY, fldr, name);
			return String.Format("{0}{1}", CONTENT_ROOT, path);
		}

	}
}